/**
 * Copyright (c) 2014-2017, huli.com
 * All rights reserved.
 */
package com.xiaohujr.xuexue.vm.gc;

/**
 * 引用计数回收.
 * 两个对象相互引用,但GC分析结果还是被回收了,所以明显不是用计数回收机制进行回收的.
 *
 * @author Xue Xue (xuexue1@huli.com)
 * @version $Id$
 * @since 2018/5/3
 */
public class ReferenceCountingGC {
    private Object instance;

    private static final int _1MB = 1024 * 1024;

    /**
     * 唯一作用就是
     */
    private byte[] bigsize = new byte[_1MB * 2];

    public static void testGC() {
        ReferenceCountingGC objA = new ReferenceCountingGC();
        ReferenceCountingGC objB = new ReferenceCountingGC();
        objA.instance = objB;
        objB.instance = objA;
        System.gc();
    }

    /**
     * VM args:-XX:+PrintGC -XX:+PrintGCDetails
     *
     * @param args
     */
    public static void main(String[] args) {
        testGC();
    }
}
